<?php
/**
 * 工具类
 * Created by PhpStorm.
 * Author: Lin
 * Date: 2017/12/20
 * Time: 21:16
 */
namespace app\base;

class Tools
{
    /**
     * 返回格式化的layui-table数据
     * @param array $data 数据集
     * @param string $msg 提示信息
     * @param int $code 状态信息
     * @return \think\response\Json
     */
    public static function tableData($data = [],$msg = '',$code = 0)
    {
        $result = ['data' => [], 'count' => 0, 'msg' => $msg, 'code' => $code];
        if ($data) {
            if (! is_array($data)) $data = $data->toArray();
            $result['data'] = $data['data'];
            $result['count'] = isset($data['total']) ?$data['total']: 0;//数据总行数
        }

        return json($result);
    }

    public static function ajaxReturn($status = true, $msg = '', $data = [])
    {
        $result['status'] = $status;
        $result['msg'] = $msg;
        $result['data'] = $data;
        return json($result);
    }
}
